GoFiler Legato Script Reference
Legato v 1.5d Application v 5.25a
|
Table of Contents | < < Previous | Next >> |
Chapter Six — File Functions (continued)
Multipurpose Internet Mail Extensions, or MIME, is used to encode complex data in the form of exchangeable simple ASCII data. This is used for email, single page web files or any other method were a series of files need to be encoded and carried with a series of parameters.
MIME data can be found as single page web files (MHT), email messages (EML) and many other multiple encoded document formats. It allows for the definition of loose parameters and encoding of various content types ranging from text based items such as HTML to binary files such as JPEGs.
As a side note, a MIME encoded files and a MIME types are not the same thing.
Legato supports a number methods to access MIME encoded information.
A MIME file generally contains a header and a series of complex data elements (parts, attachments or files) separated by a boundary layer. Each boundary layer can have its own parameters and encoding methods.
Each attachment or file can be encoded using a number of methods such as Base64 or quoted printable or 7-bit. Attached data or files may or may not have associated properties.
The MIMEGetProperties function allows the header information to be read as a table of parameter names and data.
MIME files will have at least a basic header specifying that the context is MIME encoded and specifying what is known as a boundary layer. For email messages. there are dozens of standard property names and extension properties. Further, the header may contain duplicate property names with differing data as mail relays and mail processors add information to the messages each time it is handled. The MIMEGetProperties function returns the entire decoded header as a table. As such, elements must be searched rather than conventionally using a key name. For example:
string s1, s2, s3, s4; handle hPop, hMIME; string id_list[]; int ms_list[]; string data[][]; int sx, ix, count; int rc; AddMessage("POP3 Example:"); hPop = POPConnect("mail.xxxxxxxxxxxx.com", "my user", "my password"); if (IsError(hPop)) { rc = GetLastError(); AddMessage(" FAIL: Failed to open Connection - 0x%08X", rc); exit; } AddMessage(" PASS: POPConnect"); // Get Count count = POPGetMessageCount(hPop); if (IsError(count)) { AddMessage("Failed to Get Message Count - 0x%08X", rc); exit; } if (count == 0) { AddMessage(" The Inbox is Empty -- STOPPED"); exit; } id_list = POPGetMessageIDList(hPop); ms_list = POPGetMessageSizeList(hPop); count++; // zero-inclusive // Dump Message Headers to Log AddMessage("Message List (%d messages):", count - 1); ix = 1; while (ix < count) { s1 = POPGetMessageHeader(hPop, ix); hMIME = MIMEOpen(s1); if (IsError(hMIME)) { rc = GetLastError(); s2 = ""; s3 = "--Header Error--"; s4 = FormatString("Code: 0x%08X", rc); } else { s2 = ""; s3 = ""; s4 = ""; data = MIMEGetProperties(hMIME); sx = FindInTable(data, "Date"); if (sx >= 0) { s2 = data[sx][1]; } sx = FindInTable(data, "Subject"); if (sx >= 0) { s3 = data[sx][1]; } sx = FindInTable(data, "From"); if (sx >= 0) { s4 = data[sx][1]; } CloseHandle(hMIME); } s1 = TrailStringAfter(id_list[ix], 42); s3 = TrailStringAfter(s3, 32); AddMessage(" %3d %-42s %8a bytes %-33s %-32s %s ", ix, s1, ms_list[ix], s2, s3, s4); ix++; }
In the above, the FindInTable function is used to locate the first occurrence of “Date”, “Subject” and “From”.
6.9.4 Attachments, Files and Data
Multipart data is encoded and may be files, attachments or messages. For the purposes of extraction and management, each multipart item is considered an item. Since a item may be a message or alternate, it may not be associated with a name or other typical file properties.
Each item within the MIME are separated by a content boundary. Items can also contain additional boundaries as marked by the content-type “multipart/alternative”. Data for each content is also available as an individual item. The MIMEEnumerateItems function can be used to get a list of items and their index positions. Since an item does not have to have a name, the array can have empty string entries. The properties for a specific item index can be retrieved using the MIMEGetItemProperties function. The content of an item can be extracted to a file using the MIMEItemsToFiles or MIMEItemToFile function, a string using the MIMEItemToString or a Data Object using the MIMEItemToDataObject function.
Content is not necessarily guaranteed to file associated filename. This is particularly true of email messages.
Object Management:
MIMEOpen — Opens a specified MIME encoded string or file such as an MHT or EML file.
Parameters:
MIMEGetProperties — Retrieves the available properties for a MIME Object in the form of a string table.
Item Data:
MIMEEnumerateItems — Enumerates all the item entries contained in a MIME Object.
MIMEGetItemProperties — Retrieves all available properties for a specified file within a MIME Object.
MIMEItemsToFiles — Extracts all the named items in a MIME Object to files.
MIMEItemToFile — Extracts a specified item from a MIME Object to a file.
MIMEItemToString — Extracts a specified item in a MIME Object to a string.
Table of Contents | < < Previous | Next >> |
© 2012-2024 Novaworks, LLC. All rights reserved worldwide. Unauthorized use, duplication or transmission prohibited by law. Portions of the software are protected by US Patents 10,095,672, 10,706,221 and 11,210,456. GoFiler™ and Legato™ are trademarks of Novaworks, LLC. EDGAR® is a federally registered trademark of the U.S. Securities and Exchange Commission. Novaworks is not affiliated with or approved by the U.S. Securities and Exchange Commission. All other trademarks are property of their respective owners. Use of the features specified in this language are subject to terms, conditions and limitations of the Software License Agreement.